<template>
  <view>
   <mysearch @myclick="gotosearch"></mysearch>
    <view class='scroll-item'>
      
         <scroll-view class="scroll-left" :scroll-y=true style="height: hw+'px';">
           <block v-for="(item,index) in cateList" :key="index">
             <view :class="['left-scroll-view-item',index==active?'active':'']" @click="changeitem(index)">{{item.cat_name}}</view> 
           </block>
         </scroll-view>
         <scroll-view class="scroll-right" scroll-y="true" :scroll-top="scrollTop">
           <view v-for="(item2,index2) in cateList2" :key="index2">
             <view class="catelist2">
               <text>/{{item2.cat_name}}/</text>
             </view>
             <view    class="cate3-item">
             <view class="cate3list" v-for="(item3,index3) in item2.children" 
             :key="index3" @click="gotoGoodsList(item3)">
                 <image :src="item3.cat_icon" class="item3image" mode="widthFix"></image>
                 <text>{{item3.cat_name}}</text>
                 </view>
             </view>
           </view>
         </scroll-view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
  import badge from '../../mixin/tabbar-badge.js'
    export default {
      mixins:[badge],
    data() {
      return {
        hw:0,
        active:0,
        cateList:[],
        cateList2:[],
        scrollTop:0
      };
    },
    onLoad(){
 const info= uni.getSystemInfoSync()
 this.hw=info.windowHeight-50

 this.getcateList()
    },
    methods:{
      //获取分类列表
 async     getcateList(){
   const result=await  uni.$http.reqcateList()
   if(result.statusCode!==200)return uni.$showmsg()
   
 this.cateList=result.data.message
 this.cateList2=result.data.message[0].children
 
      },
      changeitem(index){
      this.active=index
  this.cateList2=this.cateList[index].children
  this.scrollTop=this.scrollTop==0?1:0
      },
     gotoGoodsList(item3){
       uni.navigateTo({
         url:'../../subpkg/goods_list/goods_list?cid='+item3.cat_id
       })
      },
      gotosearch(){
        uni.navigateTo({
          url:'../../subpkg/search/search'
        })
      }
    }
  }
</script>

<style lang="scss">
  .scroll-item{
    display: flex;
    .scroll-left{
      width: 120px;
      .left-scroll-view-item {
        font-size: 12px;
        line-height: 60rpx;
        background-color: #f7f7f7;
        text-align: center;
       
      }
      .active{
        background-color: #FFFFFF;
        position: relative;
        &::before{
          content: '';
          display: block;
          height: 30rpx;
          width: 2px;
          background-color:red;
          position: absolute;
          top:50%;
          left:0;
          transform: translateY(-50%);
          
        }
      }
     
    }
    
  }
  .catelist2{
    font-size: 12px;
    font-weight: bold;
    text-align: center;
   padding: 15px 0;
  }
  .cate3-item{
display:flex;
flex-wrap: wrap;
 
  .cate3list{
    width:33.33%;
    display: flex;
    flex-direction: column;
   align-items: center;
   margin-bottom: 10px;
    text{
     font-size: 12px; 
     
    }
    .item3image{
      width: 60px;
      height: 60px;
      
      
    }
  }
  }
  

</style>
